@extends('Admin.layout')
@section('content')
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                管理员管理
                <small>管理员列表</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 主页</a></li>
                <li><a href="#">管理员管理</a></li>
                <li class="active">管理员列表</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">快速查看</h3>
                        </div><!-- /.box-header -->
                        <div class="box-body">
                        @if (session('info'))
                                <div class="alert alert-danger alert-dismissable">
                                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                                <h4><i class="icon fa fa-ban"></i> 提示!</h4> 
                                    <h4> {{ session('info') }}  </h4>
                                </div>
                        @endif
                        <div class='rows'>
                        <form action="{{ url('admin/manager/index') }}" method="get">
                               <!-- 分页数 -->
                                <div class="col-md-4 "> 
                                <div class="form-group">
                                
                                <select class="form-control select2" name="pages" style="width: 100%;">
                                    <option
                                    @if( !empty($request['pages']) && $request['pages']==10 )
                                    selected=true;
                                    @endif
                                    >10</option>
                                    <option
                                    <option
                                    @if( !empty($request['pages']) && $request['pages']==20)
                                    selected=true;
                                    @endif
                                    >20</option>
                                    <option
                                    @if( !empty($request['pages']) && $request['pages']==50)
                                    selected=true;
                                    @endif
                                    >50</option>
                                    <option
                                     @if( !empty($request['pages']) && $request['pages']==100)
                                    selected=true;
                                    @endif
                                    >100</option>
                                </select>
                                </div><!-- /.form-group -->
                             </div>
                            <!-- 搜索框 -->
                                <div  class="col-md-4 col-md-offset-4">
                                <div class="input-group input-group-sm ">
                                <input type="text" class="form-control" name="search" value="{{  $request['search'] or "" }}">
                                <span class="input-group-btn">
                                <button  class="btn btn-info btn-flat">搜索</button>
                                </span>
                                </div>   
                                 </div>    
                        </form>
                           

                        </div>
                        <br>
                                

                            <table id="example2" class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>管理员名</th>
                                    <th>权限</th>
                                    <th>邮箱</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>

                                @foreach($data as $v)
                                <tr>
                                    <td class='ids'>{{  $v->id }}</td>
                                    <td class='name'>{{  $v->name }}</td>
                                    <td>
                                    @if($v->rights==9)
                                    最高管理员
                                    @elseif($v->rights==3)  
                                    人事总监
                                    @elseif($v->rights==1)  
                                    企业总监
                                    @elseif($v->rights==2)  
                                    广告总监
                                    @endif
                                    </td>
                                    <td>{{  $v->email }}</td>
                                    <td class=sts>
                                    @if($v->status==0)
                                    启用
                                    @else
                                    禁用
                                    @endif
                                    </td>
                                    <td><a href="{{ url('/admin/manager/edit/') }}/{{ $v->id }}">编辑</a> |
                                          <a href="{{ url('/admin/manager/delete/') }}/{{ $v->id }}">删除</a</td>
                                </tr>
                                @endforeach
                    
                              
                    
                            </table>
                            {!! $data->appends($request)->render() !!}
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->


                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->

<script>
    window.onload=function()
    {
        $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
        });

        $('.sts').click(function(){
            var id=$(this).parent().find('.ids').html();
            var t=$(this);
            $.ajax({
                url:'/admin/manager/updatest',
                type:'post',
                data:{id:id},
                success:function(data)
                {
                    
                    if(data==0)
                    {
                        t.html('启用');
                    }else
                    {
                        t.html('禁用');

                    }               
                },
                dataType:'json'


            });
        });


// 双击改变姓名
// 
// 
     function dbl()
     {
         var t=$(this);
            //获取id
            var id=$(this).parent().find('.ids').html();
            //input value
            var oldname=$(this).html();
            //insert the input
            var inp=$("<input type='text' >");
            //set the input's value
            inp.val(oldname);
            //插入文本
            
            $(this).html(inp);
            inp.select();


            inp.blur(function(){
                var newname=inp.val();
                $.ajax({
                    url:'/admin/manager/updatena',
                    type:'post',
                    data:{id:id,name:newname},
                    success:function(data)
                    {
                        if(data==1)
                        {
                            t.html(newname);
                        }else if(data==0)
                        {
                            alert('失败');
                            t.html(oldname);
                        }else if(data==5)
                        {
                            alert('重复');
                            t.html(oldname);
                        }
                    },
                    dataType:'json'
                })

                t.on('dblclick',dbl);
            })
            t.unbind('dblclick');
     }


        
        // $('.name').dblclick('dblclick');

        $('.name').dblclick(dbl);
           
            
            // dbl();
            // $(this).unbind('dblclick');
        // })

    }
</script>
@endsection